Element.implement({
shake : function(radius,duration){
radius = radius || 3;
duration = duration || 500;
duration = (duration/50).toInt() - 1;
var parent = this.getParent();
if(parent != $(document.body) && parent.getStyle('position')=='static'){
parent.setStyle('position','relative');
}
var position = this.getStyle('position');
if(position=='static'){
this.setStyle('position','relative');
position = 'relative';
}
if(Browser.Engine.trident){
parent.setStyle('height',parent.getStyle('height'));
}
var coords = this.getPosition(parent);
if(position == 'relative' && !Browser.Engine.presto){
coords.x -= parent.getStyle('paddingLeft').toInt();
coords.y -= parent.getStyle('paddingTop').toInt();
}
var morph = this.retrieve('morph');
if (morph){
morph.cancel();
var oldOptions = morph.options;
}
var morph = this.get('morph',{
duration:50,
link:'chain'
});
for(var i=0 ; i < duration ; i++){
morph.start({
top:coords.y+$random(-radius,radius),
left:coords.x+$random(-radius,radius)
});
}
morph.start({
top:coords.y,
left:coords.x
}).chain(function(){
if(oldOptions){
this.set('morph',oldOptions);
}
}.bind(this));
return this;
}
});

Element.implement({
beat : function(radius,rate){
radius = radius || 2;
rate = rate || 70;
duration = (60000/(4*rate)).toInt();
var parent = this.getParent();
if(parent != $(document.body) && parent.getStyle('position')=='static'){
parent.setStyle('position','relative');
}
var position = this.getStyle('position');
if(position=='static'){
this.setStyle('position','relative');
position = 'relative';
}
if(Browser.Engine.trident){
parent.setStyle('height',parent.getStyle('height'));
}
var coords = this.getCoordinates(parent);
if(position == 'relative' && !Browser.Engine.presto){
coords.left -= parent.getStyle('paddingLeft').toInt();
coords.top -= parent.getStyle('paddingTop').toInt();
}
this.set('morph',{
link:'chain',
transition:Fx.Transitions.Back.easeOut,
duration:duration
}).store('coords',coords);
var hr = function(){
var coords = this.retrieve('coords');
this.morph({
top: coords.top - radius,
left: coords.left - radius,
width: coords.width + 2*radius,
height : coords.height + 2*radius
}).morph(coords);
};
hr.call(this);
hr.periodical((60000/rate).toInt(),this);
return this;
}
});

Element.implement({
zboing : function(){
var parent = this.getParent();
if(parent != $(document.body) && parent.getStyle('position')=='static'){
parent.setStyle('position','relative');
}
var position = this.getStyle('position');
if(position=='static'){
this.setStyle('position','relative');
position = 'relative';
}
if(Browser.Engine.trident || Browser.Engine.presto){
parent.setStyle('height',parent.getStyle('height'));
var coords = this.getPosition(parent);
}else{
var coords = this.getPosition(parent);
if(position == 'relative'){
coords.x -= parent.getStyle('paddingLeft').toInt();
coords.y -= parent.getStyle('paddingTop').toInt();
}
}
this.setStyle('cursor','move').store('position',coords).set('morph',{
transition:Fx.Transitions.Elastic.easeOut
}).makeDraggable({
onComplete:function(){
var position = this.element.retrieve('position');
this.element.get('morph').start({
top:position.y,
left:position.x
});
}
});
return this;
}
});

Element.implement({
followMe : function(offset){
offset = offset || 0;
var pos = this.getCoordinates();
this.inject($(document.body)).setStyles({
position:'absolute',
margin:0,
top:pos.top,
left:pos.left
}).set('morph',{
link:'cancel',
transition:Fx.Transitions.linear,
duration:1000
});
$(document.body).addEvent('mousemove',function(e){
this.store('page',{top:e.page.y+offset,left:e.page.x+offset});
}.bind(this));
var goToMouse = function(){
var page = this.retrieve('page');
if(page){
this.get('morph').start(page);
this.store('page',false);
}
}
goToMouse.periodical(100,this);
return this;
}
});

Element.implement({
confirmUnsaved : function(){
if(this.get('tag') == 'form'){
this.addEvents({
'submit' : function(){this.store('modified',false);},
'reset' : function(){this.store('modified',false);}
}).getElements('input,textarea,select').addEvent('change',function(){
this.getParent('form').store('modified',true);
});
window.onbeforeunload = function(){
if(this.retrieve('modified')){
return "You did not submit the last modifications.";
}
}.bind(this);
}
return this;
}
});